package com.own.component.device.impl;

import com.own.component.device.base.RequestDeviceManager;
import com.own.component.device.property.DeviceProperty;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * DefaultMultipleRequestDeviceManager
 *
 * @author chenxueli
 * @date 2024-03-15 11:38:12
 */
public class DefaultMultipleRequestDeviceManager extends RequestDeviceManager {

    private final List<RequestDeviceManager> managerList = new ArrayList<>();

    public DefaultMultipleRequestDeviceManager(DeviceProperty property, RequestDeviceManager... array) {
        super(property);
        for (var manager : array) {
            if (manager.getClass() != DefaultMultipleRequestDeviceManager.class) {
                managerList.add(manager);
            }
        }
    }

    /**
     * 获取客户端信息
     *
     * @return 客户端信息
     */
    @Override
    public String client(HttpServletRequest request) {
        for (var manager : managerList) {
            var client = manager.client(request);
            if (StringUtils.isNotBlank(client)) {
                return client;
            }
        }
        return null;
    }

}
